#include "StdAfx.h"
#include "TreeRenderAgent.h"

TreeRenderAgent::TreeRenderAgent(void)
{
	this->treeModel = new LifeSketchTree::CTree();
}

TreeRenderAgent::~TreeRenderAgent(void)
{
}

char * TreeRenderAgent::sketchTypeName() const
{
	return "Tree";
}

void TreeRenderAgent::renderExtra2D(int numPixels, const int pixel[][2])
{
	// Don't need any extra 2D lines
}

void TreeRenderAgent::initialize3D()
{
	// select clearing color (for glClear)
	glClearColor (1,1,1,1);	// RGB-value for white
	// enable depth buffering
	glEnable(GL_DEPTH_TEST);
	// initialize view (simple orthographic projection)
	glMatrixMode(GL_PROJECTION);
	
	// material properties 
	_mat_ambient_and_diffuse[0]=0.0;		// green material ...
	_mat_ambient_and_diffuse[1]=0.8;
	_mat_ambient_and_diffuse[2]=0.0;
	_mat_ambient_and_diffuse[3]=1;
	_mat_specular[0]=0.8f;				// ... with white highlights
	_mat_specular[1]=0.8f;				// if light source is reflected
	_mat_specular[2]=0.8f;				// on the material surface.
	_mat_specular[3]=1;
	_mat_shininess[0]=100;

	// material properties Sphere 
	_mat_ambSph[0]=0.2;		// green material ...
	_mat_ambSph[1]=0.2;
	_mat_ambSph[2]=0.2;
	_mat_ambSph[3]=1;
	_mat_specSph[0]=0.8f;				// ... with white highlights
	_mat_specSph[1]=0.8f;				// if light source is reflected
	_mat_specSph[2]=0.8f;				// on the material surface.
	_mat_specSph[3]=1;
	_mat_shinSph[0]=100;

	glMaterialfv(GL_FRONT, GL_SPECULAR, _mat_specular);
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, _mat_ambient_and_diffuse);
	glMaterialfv(GL_FRONT, GL_SHININESS, _mat_shininess);
	
	// enable shading and lighting
	glShadeModel(GL_SMOOTH);
	
	_terrain = new LifeSketchTree::CTerrain();
	_terrain->createDemoTerrain();
}

void TreeRenderAgent::generate3DModel(vector<CSketch *> sketches, int sketch_area_width, int sketch_area_height)
{
	this->treeModel->sketches = &sketches;
	this->treeModel->setSketchArea(sketch_area_width, sketch_area_height);
	this->treeModel->regenerate();
}


void TreeRenderAgent::render3D()
{
	glMatrixMode( GL_MODELVIEW );	// Set the view matrix ...
	this->treeModel->_display3D();
	_terrain->display3D();
	
	glFlush ();
}